from django.shortcuts import render

# Create your views here.
from django.views import View


from contents.utils import get_categories
from goods.models import GoodsCategory,GoodsChannel,GoodsChannelGroup
from contents.models import ContentCategory
from collections import OrderedDict




class IndexView(View):
    def get(self,request):
        '''展示首页广告'''
        categories = get_categories()
        contents = {}
        '''查询所有广告类别'''
        contents_categories = ContentCategory.objects.all()
        '''遍历所有广告类别'''
        for contents_category in contents_categories:
            '''获取查询出的没有下架的广告按排列顺序排列'''

            contents[contents_category.key] = contents_category.content_set.filter(status = True).order_by('sequence')
            '''构造上下文'''
        context = {
            'categories' : categories,
            'contents':contents,
        }

        return render(request,'index.html',context)
